package com.hkbigdata.source;

import com.hkbigdata.bean.WaterSensor;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

/**
 * @author liuanbo
 * @creat 2024-04-01-15:57
 * @see 2194550857@qq.com
 */
public class Flink01_Source_Collection {
    public static void main(String[] args) throws Exception {
        //1.执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //2.准备集合
        List<WaterSensor> waterSensors = Arrays.asList(
                new WaterSensor("ws_001", 1577844001L, 45),
                new WaterSensor("ws_002", 1577844002L, 41),
                new WaterSensor("ws_003", 1577844005L, 48)
        );

        //3.读取数据
        DataStreamSource<WaterSensor> waterSensorDataStreamSource = env.fromCollection(waterSensors);

        waterSensorDataStreamSource.print();

        //4.执行
        env.execute("flink job");



    }
}
